import { createBrowserHistory } from "history";
import React, { Component } from "react";
import { Redirect, Route, Router, Switch } from "react-router-dom";
import LoginPage from "./pages/loginPage";
import Layout from "@shared/layout";
import RouteGuard from "@shared/routeGuard";
import isLogin from "@utils/isLogin";
import DashboardPage from "@pages/dashboardPage";
import ArticlePage from '@pages/articlePage'
export const history = createBrowserHistory();

export default class App extends Component {
  render() {
    return (
      <Router history={history}>
        <Switch>
          <Redirect from="/" to="/login" exact />
          <Route path="/login" component={LoginPage} />
          <Switch>
            <Route path="/admin">
              <RouteGuard guards={[isLogin]} onRejected={() => <Redirect to="/login" push={false} />}>
                <Layout>
                  <Switch>
                    <Redirect from="/admin" to="/admin/dashboard" exact />
                    <Route path="/admin/dashboard" component={DashboardPage} />
                    <Route path="/admin/article" component={ArticlePage} />
                  </Switch>
                </Layout>
              </RouteGuard>
            </Route>
          </Switch>
        </Switch>
      </Router>
    );
  }
}
